package com.qq.financeSystem.controller;

import com.qq.financeSystem.model.MoneyModel;
import com.qq.financeSystem.model.YearAndMonth;
import com.qq.financeSystem.service.AnalyzeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/analyze")
public class AnalyzeController {

    @Autowired
    AnalyzeService analyzeService;

    //财务分析主页
    @RequestMapping("/index")
    public String index(Model m) {
        //本月收入总额
        String monthGetMoney = analyzeService.queryMonthCountMoney();
        m.addAttribute("monthGetMoney",monthGetMoney);
        //本年度收入总额
        String yearGetMoney = analyzeService.queryYearCountMoney();
        m.addAttribute("yearGetMoney",yearGetMoney);
        //本年度车辆数量
        String carCount = analyzeService.queryYearCarCount();
        m.addAttribute("carCount",carCount+"  辆");
        //累计客户
        String courses = analyzeService.queryAllCourse();
        m.addAttribute("courses",courses+"  人");
        //本月支出总额
        String monthOutMoney = analyzeService.queryMonthAllOutMoney();
        m.addAttribute("monthOutMoney",monthOutMoney);
        //本年度支出总额
        String yearOutMoney = analyzeService.queryYearAllOutMoney();
        m.addAttribute("yearOutMoney",yearOutMoney);
        //本年度车辆总量
        String yearAllCar = analyzeService.queryYearAllCar();
        m.addAttribute("yearAllCar",yearAllCar+"  辆");
        //在职人员数
        String allPerson = analyzeService.queryAllPerson();
        m.addAttribute("allPerson",allPerson+"  人");
        //本周每天车辆收入(柱状图)
        List<String> weekOneCar = analyzeService.queryWeekOneCarMoney();
        m.addAttribute("weekOneCar",weekOneCar);
        //本周每天售后收入(柱状图)
        List<String> weekOneFix = analyzeService.queryWeekOneFixMoney();
        m.addAttribute("weekOneFix",weekOneFix);
        //近12月每月车辆情况（折线图）
        List<MoneyModel> everyMonthCarMoney = analyzeService.queryTenTwoByOneCarMoney();
        m.addAttribute("everyMonthCarMoney",everyMonthCarMoney);
        //近12月每月售后情况（折线图）
        List<MoneyModel> everMonthFixMoney = analyzeService.queryTenTwoByOneFixMoney();
        m.addAttribute("everMonthFixMoney",everMonthFixMoney);
        return "lsq/analyze/analyzeSystem";
    }

    //本月支出额详情
    @RequestMapping("/showMonthOutMoney")
    public String showMonthOutMoney(Model m){
        //本月部门工资支出详情
        m.addAttribute("salary",analyzeService.queryMonthSalaryOutMoney());
        //本月仓库车辆进货
        m.addAttribute("homeCar",analyzeService.queryMonthCarHomeOutMoney());
        //本月仓库配件进货
        m.addAttribute("homePart",analyzeService.queryMonthPartHomeOutMoney());
        return "lsq/analyze/monthOutMoney";
    }

    //本年度支出额总览
    @RequestMapping("/showYearOutMoney")
    public String showYearOutMoney(Model m){
        m.addAttribute("years",analyzeService.queryYearAllOutMoneyShow());
        return "lsq/analyze/yearOutMoney";
    }

    //本年度内某月支出详细信息
    @RequestMapping("showYearToMonthOutMoney")
    public String showYearToMonthOutMoney(String yearMonth,Model m){
        if (yearMonth == null)
            return "redirect:showYearOutMoney";
        String[] split = yearMonth.split("-");
        YearAndMonth key = new YearAndMonth(split[0],split[1]);
        m.addAttribute("salary",analyzeService.queryOutYearToMonthByKey(key));
        m.addAttribute("homeCar",analyzeService.queryOutYearToMonthCarHomeByKey(key));
        m.addAttribute("homePart",analyzeService.queryOutYearToMonthPartHomeByKey(key));
        m.addAttribute("yearMonth",yearMonth);
        return "lsq/analyze/yearToMonthOutMoney";
    }

    //本月收入详情
    @RequestMapping("/showMonthGetMoney")
    public String showMonthGetMoney(Model m){
        m.addAttribute("monthCar",analyzeService.monthGetMoneyForCar());
        m.addAttribute("monthFix",analyzeService.monthGetMoneyForFix());
        return "lsq/analyze/monthGetMoney";
    }

}
